package com.redstar.study;

import java.util.List;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

public class DictionaryAdapter extends BaseAdapter implements OnClickListener {
	private Context context;
	private List<Word> listOfWords;
	
	public DictionaryAdapter(Context context, List<Word> listOfWords) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.listOfWords = listOfWords;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return listOfWords.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listOfWords.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup viewGroup) {
		// TODO Auto-generated method stub
		Word entry = listOfWords.get(position);
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.dicitionary_row, null);
        }
        
        TextView tvKanji = (TextView) convertView.findViewById(R.id.KanjiTextView);
        tvKanji.setText(entry.getKanji());

        TextView tvKana = (TextView) convertView.findViewById(R.id.KanaTextView);
        tvKana.setText(entry.getKana());

        RatingBar tvRomanji = (RatingBar) convertView.findViewById(R.id.ratingBar1);
        tvRomanji.setRating((float) entry.getRating());

        TextView tvDefinition = (TextView) convertView.findViewById(R.id.DefinitionsTextView);
        tvDefinition.setText(entry.getDefinition());
        
        TextView tvType = (TextView) convertView.findViewById(R.id.TypeTextView);
        tvType.setText(entry.getType());
 
      
		return convertView;
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub

	}

}
